package com.powernode.service.Impl;

import com.powernode.common.Page;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.powernode.domain.SysUser;
import com.powernode.mapper.SysUserMapper;
import com.powernode.service.SysUserService;

import java.util.List;

@Service
public class SysUserServiceImpl extends BaseServiceImpl implements SysUserService{

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public int deleteByPrimaryKey(Long userId) {
        return sysUserMapper.deleteByPrimaryKey(userId);
    }

    @Override
    public int insert(SysUser record) {
        return sysUserMapper.insert(record);
    }

    @Override
    public int insertSelective(SysUser record) {
        return sysUserMapper.insertSelective(record);
    }

    @Override
    public SysUser selectByPrimaryKey(Long userId) {
        return sysUserMapper.selectByPrimaryKey(userId);
    }

    @Override
    public int updateByPrimaryKeySelective(SysUser record) {
        return sysUserMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(SysUser record) {
        return sysUserMapper.updateByPrimaryKey(record);
    }

    /**
     * 登录
     * @param username
     * @param password
     * @return
     */
    @Override
    public SysUser login(String username, String password) {
        return sysUserMapper.login(username,password);
    }

    /**
     * 查询所有权限
     * @return
     */
    @Override
    public List<String> queryAllPermissions() {
        return sysUserMapper.queryAllPermissions();
    }

    /**
     * 根据id查询权限
     * @param userId
     * @return
     */
    @Override
    public List<String> queryUserPermissionsByUserId(Long userId) {
        return sysUserMapper.queryUserPermissionsByUserId(userId);
    }

    /**
     * 分页查询
     * @param page
     * @return
     */
    @Override
    public Page<SysUser> getByPage(Page<SysUser> page) {
        com.github.pagehelper.Page<SysUser> startPage = startPage(page.getPageNumber(), page.getPageSize());
        List<SysUser> sysUserList=sysUserMapper.queryAllUser(page.getParams());
        page.setTotalCount(startPage.getTotal());
        page.setList(startPage.getResult());
        return page;
    }

    /**
     * 根据用户名查询用户对象
     * @param userName
     * @return
     */
    @Override
    public SysUser queryUserByUserName(String userName) {
       return sysUserMapper.queryUserByUserName(userName);
    }

}
